
module Schnell
  class Browser
    include Schnell::Container

    #set the proxy server and port if you have one.
    def set_proxy(proxyHost = nil,proxyPort = nil)
      @proxyHost = proxyHost
      @proxyPort = proxyPort
      return [@ProxyHost,@proxyPort]
    end

    #navigate to a url
    def goto(url)
      @webclient = WebClient.new(BrowserVersion.getDefault,@proxyHost,@proxyPort) if not @proxyHost.nil?
      @webclient = WebClient.new() if @proxy.nil?
      begin
        @page = @webclient.getPage(url)
      rescue java.net.UnknownHostException,java.net.ConnectException,com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException:
        raise NavigationException
      end
      EnclosingElement.store = @page
      return self
    end

    #returns the title of the current page
    def title
      return current_page.getTitleText
    end

    #return the text in the body of the current page
    def text
      return current_page.get_body.getTextContent
    end

    #returns url of the current page
    def url
      return current_page.get_web_response.get_url.to_s
    end
    
    #returns to the previous page
    def back
      
    end

    private
    #returns the current page
    def current_page
      @webclient.current_window.enclosed_page
    end
  end
end
